package com.mc.web;

import org.apache.log4j.Logger;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mc.model.Lab;
import com.mc.model.Major;
import com.mc.model.Path;
import com.mc.model.ResearchLab;
import com.mc.model.Teacher;
import com.mc.model.Teteacherytpe;
import com.mc.model.data_download;
import com.mc.model.newsandbulletin;
import com.mc.service.IDataService;
import com.mc.service.ILabService;
import com.mc.service.IResearchLabService;
import com.mc.service.MajorService;
import com.mc.service.NewsandbulletService;
import com.mc.service.TeacherService;
import com.mc.service.TeteachertypeService;
import com.mc.utils.PathUtil;
import com.mc.utils.StringUtil;

@Controller
@RequestMapping("/rcpy")
public class RcpyAction {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(RcpyAction.class);

	@Autowired private NewsandbulletService newsandbulletService;
	@Autowired private TeteachertypeService teteachertypeService; 
	@Autowired private IResearchLabService labService;
	@Autowired private TeacherService teacherService;
	@Autowired private IDataService dataService;
	@Autowired private MajorService majorService;
	@Autowired private ILabService iLabService;
	
	private Path path = null;
	/**
	 * 本科教育
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("/bkpy")
	public String bkpy(ModelMap modelMap)
	{
		
		List<Major> majors = majorService.selectAllMajors();
		modelMap.addAttribute("majors",majors);
		List<newsandbulletin> pnewses=newsandbulletService.selectnbbytype("news", 64,0, 5);

		modelMap.addAttribute("pnewses", pnewses);
		path = PathUtil.setPathParams(new String[]{"PackageName:RencaiPeiyang","ViewName:bkjy","ViewTitle:本科培养","smenu:rcpy","mmenu:bkpy"});				
		return PathUtil.returnStr(path, modelMap);
	}
	/**
	 * 研究生教育
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("/yjspy")
	public String yjspy(ModelMap modelMap)
	{
	
		List<Lab> xkxlabs = iLabService.selectallbylabtype("学科型实验室");
		modelMap.addAttribute("xkxlabs", xkxlabs);
		List<Teteacherytpe> ts = teteachertypeService.selectAllsteacher();
		modelMap.addAttribute("ts",ts);
		List<ResearchLab> labs = labService.selectAllResearchLab();
		modelMap.addAttribute("labs",labs);
		List<data_download> dd = dataService.selectbyddtype(8, 0, 5);
		
		modelMap.addAttribute("dd", dd);
        List<Teacher> jss = teacherService.selectjs();
		
		List<Teacher> fjss = teacherService.selectfjs();
		
		modelMap.addAttribute("jss",jss);
		modelMap.addAttribute("fjss",fjss);
		path = PathUtil.setPathParams(new String[]{"PackageName:RencaiPeiyang","ViewName:yjsjy","ViewTitle:研究生培养","smenu:rcpy","mmenu:yjspy"});				
		return PathUtil.returnStr(path, modelMap);
	}
	/**
	 * 学科建设
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("/xkjs")
	public String xkjs(ModelMap modelMap)
	{
		List<Lab> xkxlabs = iLabService.selectallbylabtype("学科型实验室");
		modelMap.addAttribute("xkxlabs", xkxlabs);
		List<ResearchLab> labs = labService.selectAllResearchLab();
		modelMap.addAttribute("labs",labs);
		List<data_download> dd = dataService.selectbyddtype(8, 0, 5);
		
		modelMap.addAttribute("dd", dd);
        List<Teacher> jss = teacherService.selectjs();
		
		List<Teacher> fjss = teacherService.selectfjs();
		
		modelMap.addAttribute("jss",jss);
		modelMap.addAttribute("fjss",fjss);
		List<Lab> sjzdlabs = iLabService.selectallbylabtype("省重点实验室");
		modelMap.addAttribute("sjzdlabs", sjzdlabs);
		path = PathUtil.setPathParams(new String[]{"PackageName:RencaiPeiyang","ViewName:xuekejianshe","ViewTitle:学科建设","smenu:ScienceYJ","mmenu:xkjs"});				
		return PathUtil.returnStr(path, modelMap);
	}
	/**
	 * 
	 * @param modelMap
	 * @param id 学科建设的文章id
	 * @return 展示文章的界面
	 */
	@RequestMapping("/xkjs/detail/{id}")
	public String xkdtail(ModelMap modelMap,@PathVariable("id")int id){
		Lab lab = iLabService.selectByPrimaryKey(id);
		modelMap.addAttribute("lab",lab);
		List<Teacher> teacher = teacherService.selectbybid(id);
		//logger.info(teacher.toString());
		
		modelMap.addAttribute("teacher",teacher);
		path = PathUtil.setPathParams(new String[]{"PackageName:RencaiPeiyang","ViewName:xkdetail","ViewTitle:"+lab.getLabName()+"简介","smenu:ScienceYJ","mmenu:xkjs","mmmenu:other"});				
		return PathUtil.returnStr(path, modelMap);
	}
	/**
	 * 
	 * @param modelMap
	 * @param id 研究所id 
	 * @return 研究所简介
	 */
	@RequestMapping("/detail/{id}")
	public String rcpydtail(ModelMap modelMap,@PathVariable("id")int id){
		ResearchLab lab = labService.selectByPrimaryKey(id);
		modelMap.addAttribute("lab",lab);
		List<Teacher> teacher = teacherService.selectBylabid(id);
		//logger.info(teacher.toString());
		Teacher suozhang = teacherService.selectbypositionabid(id, "所长");
		//logger.info(suozhang.toString());
		modelMap.addAttribute("suozhang",suozhang);
		modelMap.addAttribute("teacher",teacher);
		path = PathUtil.setPathParams(new String[]{"PackageName:RencaiPeiyang","ViewName:detail","ViewTitle:研究所简介","smenu:rcpy","mmenu:yjspy","mmmenu:other"});				
		return PathUtil.returnStr(path, modelMap);
	}
	/**
	 * 
	 * @param modelMap
	 * @param id 专业id
	 * @return 专业简介界面
	 */
	@RequestMapping("/bkdetail/{id}")
	public String bkdtail(ModelMap modelMap,@PathVariable("id")int id){
	    Major major = majorService.selectByPrimaryKey(id);
	    modelMap.addAttribute("major",major);
	    List<Teacher> teachers = teacherService.selectAllteacherbymajorid(id);
		modelMap.addAttribute("teachers", teachers);
		path = PathUtil.setPathParams(new String[]{"PackageName:RencaiPeiyang","ViewName:bkdetail","ViewTitle:专业简介","smenu:rcpy","mmenu:bkpy","mmmenu:other"});				
		return PathUtil.returnStr(path, modelMap);
	}
	/**
	 * 
	 * @param modelMap
	 * @param id 专业id
	 * @return 本科培养展示界面
	 */
	@RequestMapping("/bkplan/{id}")
	public String bkplan(ModelMap modelMap,@PathVariable("id")int id){
	    Major major = majorService.selectByPrimaryKey(id);
	    modelMap.addAttribute("major",major);
	    List<Teacher> teachers = teacherService.selectAllteacherbymajorid(id);
		modelMap.addAttribute("teachers", teachers);
		path = PathUtil.setPathParams(new String[]{"PackageName:RencaiPeiyang","ViewName:bkplan","ViewTitle:培养计划简介","smenu:rcpy","mmenu:bkpy","mmmenu:other"});				
		return PathUtil.returnStr(path, modelMap);
	}
}
